package com.mooc.ppjoke.ui;

import android.annotation.SuppressLint;

import androidx.annotation.NonNull;
import androidx.arch.core.executor.ArchTaskExecutor;
import androidx.paging.PageKeyedDataSource;
import androidx.paging.PagedList;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @ClassName: MutableDataSource$
 * @Description: java类作用描述
 * @Author: 魏靳元
 * @CreateDate: 2022/8/20 10:12
 * @UpdateRemark: 更新内容
 * @Version: 1.0
 */
public class MutableDataSource<Key,Value> extends PageKeyedDataSource<Key,Value> {
    public List<Value> data=new ArrayList<>();
    @SuppressLint("RestrictedApi")
    public PagedList<Value>  buildPaagedList(PagedList.Config config){
       return  new PagedList.Builder<Key, Value>(this, config)
                .setFetchExecutor(ArchTaskExecutor.getIOThreadExecutor())
                .setNotifyExecutor(ArchTaskExecutor.getMainThreadExecutor())
                .build();
    };
    @Override
    public void loadInitial(@NonNull @NotNull LoadInitialParams<Key> params, @NonNull @NotNull LoadInitialCallback<Key, Value> callback) {
        callback.onResult(data, null, null);
    }

    @Override
    public void loadBefore(@NonNull @NotNull LoadParams<Key> params, @NonNull @NotNull LoadCallback<Key, Value> callback) {
        callback.onResult(Collections.emptyList(), null);
    }

    @Override
    public void loadAfter(@NonNull @NotNull LoadParams<Key> params, @NonNull @NotNull LoadCallback<Key, Value> callback) {
        callback.onResult(Collections.emptyList(), null);
    }
}
